/***************************************************************************
*   Copyright (C) 2010-2011 by swkyer <swkyer@gmail.com>                  *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/
#ifndef __JTAGDEV_H__
#define __JTAGDEV_H__

#ifdef JTAGDEV_EXPORTS
    #ifdef WIN32
        #ifdef __cplusplus
            #define JTAGDEV_API extern "C" __declspec(dllexport)
        #else
            #define JTAGDEV_API __declspec(dllexport)
        #endif
    #else	//Linux
        #ifdef __cplusplus
            #define JTAGDEV_API extern "C"
        #else
            #define JTAGDEV_API
        #endif
    #endif
#else
    #ifdef WIN32
        #ifdef __cplusplus
            #define JTAGDEV_API extern "C" __declspec(dllimport)
        #else
            #define JTAGDEV_API __declspec(dllimport)
        #endif
    #else	//Linux
        #ifdef __cplusplus
            #define JTAGDEV_API extern "C"
        #else
            #define JTAGDEV_API
        #endif
    #endif
#endif


#include "Tap.h"


typedef struct __jtagdev
{
    void *handle;

    void *(* open)(jtagdev_cfg_t *pcfg);
    int (* close)(void *phandle);
    void *(* reinit)(void *phandle);
    int (* is_target_connect)(void *phandle);
    int (* trst_activate)(void *phandle);
    int (* trst_deactivate)(void *phandle);
    int (* rst_activate)(void *phandle);
    int (* rst_deactivate)(void *phandle);

    int (* tap_reset)(void *phandle, int use_trst);
    int (* runtest_idle)(void *phandle);

    tap_state_t (* get_tap_state)(void *phandle);
    int (* tap_moveto)(void *phandle, tap_state_t dest);

    int (* data)(void *phandle, ubase_t data_out, ubase_t *pdatain);
    int (* instruction)(void *phandle, ubase_t ir_out, ubase_t *pirin);
} jtagdev_t;


JTAGDEV_API jtagdev_t *jtagdev_open(jtagdev_cfg_t *pcfg);
JTAGDEV_API int jtagdev_close(jtagdev_t *pjtag);
JTAGDEV_API jtagdev_t *jtagdev_reinit(jtagdev_t *pjtag);

JTAGDEV_API int jtagdev_is_target_connect(jtagdev_t *pjtag);

JTAGDEV_API int jtagdev_trst_activate(jtagdev_t *pjtag);
JTAGDEV_API int jtagdev_trst_deactivate(jtagdev_t *pjtag);
JTAGDEV_API int jtagdev_rst_activate(jtagdev_t *pjtag);
JTAGDEV_API int jtagdev_rst_deactivate(jtagdev_t *pjtag);

JTAGDEV_API int jtagdev_tap_reset(jtagdev_t *pjtag, int use_trst);
JTAGDEV_API int jtagdev_runtest_idle(jtagdev_t *pjtag);

JTAGDEV_API tap_state_t jtagdev_get_tap_state(jtagdev_t *pjlink);
JTAGDEV_API int jtagdev_tap_moveto(jtagdev_t *pjlink, tap_state_t dest);

JTAGDEV_API int jtagdev_data(jtagdev_t *pjtag, ubase_t data_out, ubase_t *pdatain);
JTAGDEV_API int jtagdev_instruction(jtagdev_t *pjtag, ubase_t ir_out, ubase_t *pirin);


#endif /* end of __JTAGDEV_H__ */
